package edu.sctu.java.advanced.pattern.proxy.lab02;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserActionProxy implements InvocationHandler {
    private Object target;

    public UserActionProxy(Object target) {
        this.target = target;
    }

    public Object getProxyInstance(){

        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                this
        );
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("Before invoke:");
        Object obj = method.invoke(target, args);
        return obj;
    }
}
